package cn.com.simple.learning.designpattern.behavior.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jjx
 * @date 2021/7/20 16:06
 */
public class Topic {

    private final List<Observer> observers = new ArrayList<>();
    private int state;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        this.notifyObservers();
    }

    private void notifyObservers() {
        observers.forEach(Observer::update);
    }

    public void register(Observer observer) {
        observers.add(observer);
    }

}
